package response

import "encoding/json"

type DataRes struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func SuccessRes(data interface{}) ([]byte, error) {
	res := DataRes{
		Code:    200,
		Message: "成功",
		Data:    data,
	}
	return json.Marshal(res)
}

func ErrorRes(msg string, code int) ([]byte, error) {
	res := DataRes{
		Code:    code,
		Message: msg,
		Data:    nil,
	}
	return json.Marshal(res)
}